<template>
  <view class="index" v-if="token">
    <image
      v-for="i in 30"
      :key="i"
      :src="`/static/index/image_${i}.jpeg`"
      mode="widthFix"
      class="img"
    />

    <view class="btn-bottom">
      <button class="next-btn" @tap="nextStep">马上体验</button>
    </view>
  </view>
</template>

<script setup>
  import sheep from '@/sheep';
  import { ref } from 'vue';
  import ReportApi from '@/sheep/api/report';
  import { onLoad } from '@dcloudio/uni-app';

  const { getToken } = ReportApi;

  const token = ref('');

  onLoad(async (e) => {
    const options = e
    const queryObj = Object.assign({}, options);

    if (options.token) {
      // queryObj.open = queryObj.open || 0;

      if(!queryObj.open) {
        queryObj.open = 0;
        const queryStr= Object.entries(queryObj).map(([k,v]) => `${k}=${v}`).join('&')
        window.location.href = `${window.location.href.replace(/\?.*$/g, '')}?${queryStr}`
        return
      }
    } else {
      const res = await getToken();
      queryObj.open = queryObj.open || 1;
      queryObj.token = res.data.accessToken;
      const queryStr= Object.entries(queryObj).map(([k,v]) => `${k}=${v}`).join('&')
      window.location.href = `${window.location.href.replace(/\?.*$/g, '')}?${queryStr}`
      return
    }

    token.value = e.token;
    uni.setStorageSync('token', e.token);
  });

  const nextStep = () => {
    sheep.$router.go(`/pages/base-info/index?token=${token.value}`);
  };
</script>

<style lang="scss" scoped>
  .index {
    .img {
      display: block;
      width: 100%;
    }

    .btn-bottom {
      margin-top: -120rpx;

      height: 300rpx;
      //   background-color: red;

      .next-btn {
        width: 80% !important;
        height: 80rpx;
        // border-radius: 16rpx;
        background-color: #0d232c;
        color: white;
        font-size: 32rpx;
        opacity: 0;
      }
    }
  }
</style>
